<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        //数组去重
        //原型链上编程，
        //Array.prototype.unique = function(){}


        //1:把数组分成一个一个的对象
        //2：将对象进行遍历，如果对象的值相等，则删除该属性;
        //3:将对象再分成数组
        var arr= [1,1,1,2,3,'a',3,4,'a',4,5,'c',3,4,5,3,2,6,78,9,5,4,3,7,8,];
        Array.prototype.unique = function(){
            var obj = {};
            var newArr = [];
            for(var i = 0 ; i < this.length ; i ++){
                obj[i] = this[i];
                for(var j = this.length-1; j>i;j--){    
                    if(obj[i] == this[j]){
                        delete(obj[i]);
                        break;
                    }
                }
            }
            for(var prop in obj){
                newArr.push(obj[prop]);
            }
            return newArr;
        }
        

        //数组去重
        //循环取出数组的每一位，作为对象的属性名，判断如果存在属性名，则已经取过了不用取了

        Array.prototype.unique1 = function(){
            var obj = {};
            var newArr = [];
            for(var i = 0; i < this.length; i ++){
                if(!obj[this[i]]){
                    obj[this[i]] = 'abc';
                    newArr.push(this[i]);
                }
            }
            return newArr;
        }
    </script>
</body>
</html>